package com.tj.jinzao.fragment;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;

import com.tj.jinzao.R;
import com.tj.jinzao.adapter.MyLiveListItemAdapter;
import com.tj.jinzao.base.BaseDataListFragment;
import com.tj.jinzao.callback.IListView;
import com.tj.jinzao.model.LivePersonBean;
import com.tj.jinzao.presenter.MyLivePresenter;
import com.tj.jinzao.widgets.EmptyView;

import java.util.List;

/**
 * 病例报告列表fragment
 * Created by wjy on 2019/1/1.
 */
public class MyLiveListFragment extends BaseDataListFragment<List<LivePersonBean>, MyLivePresenter, LivePersonBean> implements IListView<List<LivePersonBean>> {

    private boolean mRevert=true;

    public static MyLiveListFragment newInstance(long uId) {
        MyLiveListFragment fragment = new MyLiveListFragment();
        if (fragment != null) {
            Bundle args = new Bundle(3);
            args.putString(ARG_TAG_ID, String.valueOf(uId));
            args.putInt(ARG_LOAD_ID, 1);
            args.putInt(ARG_LAYOUT_RES_ID, R.layout.live_fragment_item_layout);
            fragment.setArguments(args);
        }
        return fragment;
    }
    public void setRevert(boolean revert) {
        if (mRevert != revert) {
            mRevert = revert;
            refresh();
        }
    }


    @Override
    public void onRequestNoData(String message) {
        setEmptyDataView();
    }

    @Override
    protected MyLivePresenter createPresenter() {
        return new MyLivePresenter(this);
    }

    @Override
    protected void createView(LayoutInflater inflater, View view) {
    }

    @Override
    protected RecyclerView.Adapter createAdapter() {
        return new MyLiveListItemAdapter(mContext, mData);
    }

    @Override
    protected void requestData() {
        mPresenter.getLiveList(Long.parseLong(mTag),mPageNo,mRevert ? "desc" : "asc");
    }

    @Override
    protected void setEmptyDataView() {
        mEmptyView.setVisibility(View.VISIBLE);
        mEmptyView.setState(EmptyView.State.NO_DATA, "没有内容哦");
    }

    @Override
    protected boolean resolveData(List<LivePersonBean> cases) {
        return false;
    }

    @Override
    public void onRequestSuccess(List<LivePersonBean> list) {
        super.onRequestSuccess(list);
        if (mPageNo <= 1) {
            mData.clear();
        }
        mData.addAll(list);
        showListView();

    }

    @Override
    protected boolean canLoadMoreItems() {
        return false;
    }

    @Override
    protected void initData() {
    }

    @Override
    protected void itemClicked(int position, LivePersonBean data) {
    }

    @Override
    public void onRequestSuccessPage(int currentPage, int allPage, int allSize) {
        mPageNum = allPage;
    }

    @Override
    public void onReload(Object tag) {

    }
}
